package sis.ui;

import javax.swing.*;
import java.awt.event.*;
import sis.studentinfo.*;

public class Sis {
	static final int WIDTH = 350;
	static final int HEIGHT = 500;
	private JFrame frame = new JFrame();
	private CoursesPanel panel;
	
	public static void main(String[] args) {
		new Sis().show();
	}
	
	void close() {
		frame.dispose();
	}
	
	public Sis() {
		initialize();
	}
	
	private void initialize() {
		createCoursesPanel();
		
		frame.setSize(WIDTH, HEIGHT);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(panel);
	}
	
	void createCoursesPanel() {
		panel = new CoursesPanel();
		panel.addCoursesAddListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					addCourse();
				}
			}
		);
	}
	
	private void addCourse() {
		Course course = 
			new Course(
				panel.getText(CoursesPanel.DEPARTMENT_FIELD_NAME),
				panel.getText(CoursesPanel.NUMBER_FIELD_NAME));
		panel.addCourses(course);
	}
	
	public void show() {
		frame.setVisible(true);
	}
	
	JFrame getFrame() {
		return frame;
	}
}